package com.example.fpe_vote.db2.controller;


import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.example.fpe_vote.common.Result;
import com.example.fpe_vote.db1.entity.PrizeInfo;
import com.example.fpe_vote.db2.entity.Ygzlw;
import com.example.fpe_vote.db2.service.IYgzlwService;
import com.example.fpe_vote.vo.request.RequestLoginCheckVo;
import com.example.fpe_vote.vo.response.ResponseGetAllVo;
import com.example.fpe_vote.vo.response.ResponseSelectPrizeVo;
import com.example.fpe_vote.vo.response.ResponseSelectYgzlVo;
import com.example.fpe_vote.vo.response.ResponseUserInfoVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2022-12-01
 */
@RestController
@RequestMapping("/ygzlw")
@DS("slave_1")
public class YgzlwController {
    @Autowired
    IYgzlwService ygzlwService;

//    @PostMapping("/getAll")
//    public Result getAll(){
//        List<ResponseGetAllVo> voList=new ArrayList<>();
//        List<Ygzlw> ygzlwList=ygzlwService.list();
//        for(Ygzlw ygzlw:ygzlwList){
//            ResponseGetAllVo vo=new ResponseGetAllVo();
//            BeanUtils.copyProperties(ygzlw,vo);
//            voList.add(vo);
//        }
//        return Result.getSuccess().setData(voList);
//    }

    //登录验证接口
    @PostMapping("/loginCheck")
    public Result loginCheck(@RequestBody RequestLoginCheckVo vo){
        if(ObjectUtils.isEmpty(vo.getSfz())){
            return Result.getFailure().setMsg("请输入正确的身份证后六位！");
        }
        if(ObjectUtils.isEmpty(vo.getUserName())){
            return Result.getFailure().setMsg("请输入正确的姓名！");
        }
        if(ObjectUtils.isEmpty(vo.getWorkerNo())){
            return Result.getFailure().setMsg("请输入正确的工号！");
        }
        ResponseUserInfoVo userInfoVo=ygzlwService.queryOne(vo);
        if(ObjectUtils.isEmpty(userInfoVo)){
            return Result.getFailure().setMsg("您的职工信息验证失败,请确认工号、姓名或身份证是否有误！");
        }else{
            return Result.getSuccess().setData(userInfoVo).setMsg("职工信息验证成功！");
        }
    }

    @PostMapping("/selectYgzl")
    public Result selectYgzl(){
        List<ResponseSelectYgzlVo> list=new ArrayList<>();
        List<Ygzlw> ygzlws=ygzlwService.list();
        for(Ygzlw ygzlw:ygzlws){
            ResponseSelectYgzlVo vo=new ResponseSelectYgzlVo();
            BeanUtils.copyProperties(ygzlw,vo);
            list.add(vo);
        }
        return Result.getSuccess().setData(list);
    }


}
